import matplotlib.pyplot as plt

def plot_loss_and_metric(plt_dict, loss_his, loss_his_val, metric_his, metric_his_val, base_epoch=0):
    x = range(base_epoch + 1, base_epoch + 1 +len(loss_his))

    plt_dict['spn'] += 1
    plt.subplot(plt_dict['spr'], plt_dict['spc'], plt_dict['spn'])
    plt.plot(x, loss_his, label='train loss')
    plt.plot(x, loss_his_val, label='val loss')
    plt.legend()

    plt_dict['spn'] += 1
    plt.subplot(plt_dict['spr'], plt_dict['spc'], plt_dict['spn'])
    plt.plot(x, metric_his, label='train acc')
    plt.plot(x, metric_his_val, label='val acc')
    plt.legend()
